{% extends "base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load dv_filters %}
{% block head_title %}{% with canton=mcv.canton|canton_abbr:False monthyear=mcv.date|date:'F Y' %}{% blocktrans %}{{ canton }}: Validation pour {{ monthyear }}{% endblocktrans %}{% endwith %}{% endblock %}

{% block bootstrap3_extra_head %}
    {{ form.media.css }}
{% endblock %}

{% block content %}
    <h1>{% with canton=mcv.canton|canton_abbr:False monthyear=mcv.date|date:'F Y' %}{% blocktrans %}{{ canton }}: Validation pour {{ monthyear }}{% endblocktrans %}{% endwith %}</h1>
    <form method="POST" class="form-horizontal" id="urls-validator">
        {% csrf_token %}
        {% for field in form %}
            {% if field.name != 'validated' %}
                {% bootstrap_field field layout='horizontal' size='small' %}
            {% endif %}
        {% endfor %}
        <div class="form-group form-group-sm">
          <b class="col-md-3 control-label">{% trans "N’oubliez pas de valider vos factures d’établissement" %}</b>
          <div class="col-md-9">
              <div class="help-block"><a href="{% url 'invoices-yearly-list' year=mcv.date.year %}" target="_blank">{% blocktrans with year=mcv.date.year %}Factures {{ year }}{% endblocktrans %}</a></div>
          </div>
        </div>
        {% bootstrap_field form.validated layout='horizontal' size='small' %}
        {% buttons %}
            <button type="submit" class="btn btn-primary pull-right">{% trans "Enregistrer" %}</button>
            <a class="btn btn-default" href="{% url 'salary:validations-month' year=mcv.date.year month=mcv.date.month %}">{% trans "Annuler" %}</a>
        {% endbuttons %}
    </form>
{% endblock %}

{% block bootstrap3_extra_script %}
{{ form.media.js }}
<script type="text/javascript">
function cannotValidateUnlessAllURlsTicked() {
  var all_checked = true;

  $('#urls-validator').find('input[type="checkbox"]:not(#id_validated)').each(function(i, obj) {
    if(!$( this ).prop("checked")) {
      all_checked = false;
    }
  })
  $('#urls-validator').find('input[type="checkbox"]#id_validated').each(function(i, obj) {
    $( this ).prop('disabled', !all_checked);
    if (!all_checked) {
      $( this ).prop('checked', false);
    }
  })
}

$('#urls-validator').find('input[type="checkbox"]').change( cannotValidateUnlessAllURlsTicked );

cannotValidateUnlessAllURlsTicked();
</script>
{% endblock %}
